package com.jic.manager.controller.manage.merchant;

import com.jic.common.base.vo.RestResult;
import com.jic.manager.entity.MerchantWeBankFinance;
import com.jic.manager.request.MerchantWeBankFinanceRequest;
import com.jic.manager.service.MerchantWeBankFinanceService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 商户财务信息控制器
 * @autho mj
 */
@RestController
@RequestMapping("merchantWeBankFinance")
@Slf4j
public class MerchantWeBankFinanceController {

    @Resource
    private MerchantWeBankFinanceService merchantWeBankFinanceService;


    /**
     * 商户财务详情
     * @param request
     * @return
     */
    @PostMapping("/getMerchantFinanceByMerchantId")
    @ResponseBody
    @ApiOperation(value = "商户详情")
    public RestResult<MerchantWeBankFinance> getMerchantFinanceByMerchantId(@RequestBody MerchantWeBankFinanceRequest request) {
        try {
            log.debug("getMerchantInfo " + request);
            MerchantWeBankFinance merchantWeBankFinance = merchantWeBankFinanceService.getMerchantFinanceByMerchantId(request.getMerchantId());
            return RestResult.success(merchantWeBankFinance);
        }catch (Exception e){
            log.error("Manager getLotteryThemeInfo error：",e);
            return RestResult.error("9999","系统异常，财务详情查询失败");
        }
    }

    /**
     * 新增or编辑商户财务信息
     * @param request
     * @return
     */
    @PostMapping(value = "/addMerchantFinanceInfo")
    public RestResult<Long> editMerchantInfo(@RequestBody MerchantWeBankFinanceRequest request){
        try {
            log.debug("getMerchantInfo " + request);
            if(request.getId()==null){
                return RestResult.success( merchantWeBankFinanceService.addMerchantFinanceInfo(request));
            }else{
                return RestResult.success(merchantWeBankFinanceService.updateMerchantFinanceInfo(request));
            }

        }catch (Exception e){
            log.error("Manager addMerchantFinanceInfo error：",e);
            return RestResult.error("9999","系统异常，新增财务信息失败");
        }
    }


}
